
package com.freeme.cameraplugin.largemode;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.Log;
import android.view.ViewGroup;

import com.freeme.camera.BasePluginImpl;
import com.freeme.camera.CameraInterfaceManage;
import com.freeme.camera.data.PictureSizeInfo;

public class LargeMode extends BasePluginImpl {
    private static final String TAG = "LargeMode";
    private String mPackageName;
    private LargeModeManager mLargeModeManager = null;

    public LargeMode() {
        super();
    }

    @SuppressWarnings("static-access")
    public LargeMode(Context c, String pkgName) {
        super(c, pkgName);
        mPackageName = pkgName;
        Log.i(TAG,
                "CameraInterfaceManage.getInstance().mICameraExt = "
                        + (CameraInterfaceManage.getInstance().cameraExt == null));
        mLargeModeManager = LargeModeManager.getInstance(mContext,
                CameraInterfaceManage.getInstance().cameraExt);
    }

    @Override
    public int getModuleID() {
        return 103;
    }

    @Override
    public Drawable getModuleIcon() {
        return mContext.getResources().getDrawable(R.drawable.entry_icon);
    }

    @Override
    public String getPkgName() {
        return mPackageName;
    }

    @Override
    public String getModuleTitle() {
        return mContext.getString(R.string.app_name);
    }

    @Override
    public void showPanel(ViewGroup root) {
        if (root != null) {
            show(root);
        }
    }

    @Override
    public void hidePanel() {
        hide();
    }

    @Override
    public void switchPanel(ViewGroup root) {
    }

    @Override
    public byte[] blendOutput(byte[] jpegData) {
        return null;
    }

    public void mediaSaved(Uri uri) {
        if (uri != null) {
            mLargeModeManager.getHander().obtainMessage(LargeModeManager.MSG_PICTURE_SAVED, uri)
                    .sendToTarget();
        }

    }

    private void show(ViewGroup root) {
        Log.i(TAG, "show");
        mLargeModeManager.show(root);
    }

    private void hide() {
        mLargeModeManager.hide();
    }

    @Override
    public void onOrientationChanged(int orientation) {
        mLargeModeManager.onOrientationChanged(orientation);
    }

    @Override
    public PictureSizeInfo getPictureSizeInfo() {
        PictureSizeInfo info = new PictureSizeInfo(0, 0);
        info.setExpectOutImageSize(2 * 1024 * 1024);
        info.setExpectScreenRatio(16d / 9);
        return info;
    }

    @Override
    public boolean isInterceptCapture() {
        return mLargeModeManager.isViertical();
    }
}
